﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nage.Algorithms.Population;
using Nage.Algorithms.RandomGenerators;
using Nage.Algorithms.Evolution;
using Nage.Examples.Rastrigin.Solution;

namespace Nage.Examples.Rastrigin.Evolution
{
    public class CoordinatesMutation : ISolutionMutation<Coordinates>
    {
        public Double MutationRate { get; private set; }
        public Double Delta { get; private set; }

        public CoordinatesMutation(double mutationRate, double delta)
        {
            MutationRate = mutationRate;
            Delta = delta;
        }

        public Coordinates Mutate(Coordinates solution)
        {
            Coordinates mutSolution = new Coordinates(solution.X, solution.Y);
            if (Rng.GetInstance().Draw(MutationRate))
            {
                mutSolution.X += Rng.GetInstance().GetDouble(-Delta, Delta);
            }
            if (Rng.GetInstance().Draw(MutationRate))
            {
                mutSolution.Y += Rng.GetInstance().GetDouble(-Delta, Delta);
            }
            return mutSolution;
        }

    }
}
